package system.track;

/**
 * This class proveds special behavior for the parking block.
 * Specifically it overrides critical items and provides setters
 * for the blocks needed.
 *
 * @author David Kolb
 * @version Cycle 1 - complete
 */
public class Block4 extends GenericBlock implements Block
{
    private boolean parking;
    private Switch cwParkingSwitch;
    private Switch ccwParkingSwitch;
    private Block cwParkingBlock;
    private Block ccwParkingBlock;

    /**
     * Constructor for Objects of class Block4.
     */
    public Block4()
    {
        super();
    }

    /**
     * Sets the selected Switch in the Direction indicated to be a 
     * parking Switch.
     * 
     * @param d a Direction
     * @param s the Switch to be set
     */
    public void setParkingSwitch(Direction d, Switch s)
    {
        switch(d)
        {
            case CLOCKWISE:
                this.cwParkingSwitch = s;
                break;
            case COUNTERCLOCKWISE:
                this.ccwParkingSwitch = s;
                break;
            default:
                throw new IllegalArgumentException("Bad direction arg.");
        }
    }

    /**
     * Designates the Block in the selection Direction to be a parking
     * Block.
     * 
     * @param d a Direction
     * @param b the Block which will be a parking Block
     */
    public void setParkingBlock(Direction d, Block b)
    {
        switch(d)
        {
            case CLOCKWISE:
                this.cwParkingBlock = b;
                break;
            case COUNTERCLOCKWISE:
                this.ccwParkingBlock = b;
                break;
            default:
                throw new IllegalArgumentException("Bad direction arg.");
        }
    }

    /**
     * Overridden method:  this method will always return true because
     * this type of Block will always be a parking Block.
     * 
     * @return <code>true</code> if the block can park trains
     */
    @Override
    public boolean isParkingBlock()
    {
        return true;
    }

    /**
     * Indicates whether or not this Block is currently parking a train.
     * Overridden because the Block is always capable of parking a 
     * train.
     * 
     * @param flag <code>true</code> to park the train, <code>false</code> to 
     * allow the train to cross over.
     * @see Block#isParkingBlock() 
     */
    @Override
    public void setPark(boolean flag)
    {
        if (flag)
        {
            //sets the switches to let the train ride through
            this.ccwParkingSwitch.setAngle(SwitchAngle.NINETY_DEGREES);
            this.cwParkingSwitch.setAngle(SwitchAngle.NINETY_DEGREES);
        }
        else
        {
            //sets the switches to divert the train to a parking area
            this.ccwParkingSwitch.setAngle(SwitchAngle.ONE_EIGHTY_DEGREES);
            this.cwParkingSwitch.setAngle(SwitchAngle.ONE_EIGHTY_DEGREES);
        }
    }
}
